package day7.HomeWork;

import java.util.*;

//a.实现斗地主随机发牌的功能 一共54张牌
//牌的花色分为   梅花   红桃   黑桃  方片
//牌有  3 4 5 6 7 8 9 10 J Q K DemoA 2 大王 小王
//随机发给两个农民 和一个地主      地主 多三张牌
//最后显示每人的牌的结果  并且每人的排要根据牌的大小进行降序排列
public class A {
    public static void main(String[] args) {
        Comparator<Card> com = (o1,o2)->{
            int i = o2.num-o1.num;
            if (i == 0) i = o1.str.compareTo(o2.str);
            return i;
        };
        //地主
        Set<Card> set = new TreeSet<>(com);
        //农民1
        Set<Card> set1 = new TreeSet<>(com);
        //农民2
        Set<Card> set2 = new TreeSet<>(com);

        //定义所有牌对象   定义存储list所有排对象
        String[] color = {"♣", "♦", "♠", "♥"};
        String[] num = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "DemoA", "2"};
        List<Card> cards = new ArrayList<>();
        for (String s : color) {
            for (int i = 0; i < num.length; i++) {
                cards.add(new Card(s + num[i], i + 3));
            }
        }
        cards.add(new Card("小🃏", 16));
        cards.add(new Card("大🃏", 17));
        //System.out.println(cards);

        Collections.shuffle(cards); //打乱顺序
        int n = 0;
        for (int i = 0; i < 17; i++) {
            set.add(cards.get(n));
            cards.remove(n);
            set1.add(cards.get(n));
            cards.remove(n);
            set2.add(cards.get(n));
            cards.remove(n);
        }

        set.addAll(cards);
        System.out.println("地主:" + set);
        System.out.println("农民:" + set1);
        System.out.println("农民:" + set2);
    }
}

class Card {
    String str; //存储内容  ♣10
    int num;    //存储排对应的数值

    public Card(String str, int num) {
        this.str = str;
        this.num = num;
    }

    @Override
    public String toString() {
        return str;
    }
}